/*****************************************************************************

File:   otkCreateIntfDataExample.java

Date          Build     Author        Version    Comments
27-Dec-12    P-20-20    dshah          $$1        Created
20-mar-15 P-30-05 gshmelev $$2  called GetCurrentSession

****************************************************************************/

/* This example covers the creation of interfaceData from the dumped info files of OTK Java example 
otkCreateIntfData.java using models extrude_p10.prt, interface_import.prt, surface_rev.prt */

package com.ptc.otkjavaexamples;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcSession.*;
import com.ptc.pfc.pfcCommand.*;
import com.ptc.pfc.pfcGlobal.*;
import com.ptc.pfc.pfcModel.*;
import com.ptc.pfc.pfcModelItem.*;
import com.ptc.pfc.pfcFeature.*;
import com.ptc.pfc.pfcSolid.*;
import javax.swing.JOptionPane;
import java.io.*;

import com.ptc.cipjava.*;
import com.ptc.pfc.pfcFamily.*;
import com.ptc.pfc.pfcServer.*;
import com.ptc.pfc.pfcWindow.*;
import com.ptc.wfc.wfcSolid.*;
import com.ptc.wfc.wfcCombState.*;
import com.ptc.pfc.pfcBase.*; 
import com.ptc.pfc.pfcGeometry.*;
import com.ptc.wfc.wfcGeometry.*;
import com.ptc.wfc.wfcModel.*;
import com.ptc.pfc.pfcPart.*;
import com.ptc.wfc.wfcPart.*;
import com.ptc.wfc.wfcSession.*;


class otkCreateIntfDataExample extends DefaultUICommandActionListener
{
    
    public otkCreateIntfDataExample(String inMethod) 
	{ 
		mMethod = inMethod; 
	}
    
    
    public void OnCommand()
    {
	addCreateIntfDataExample();
    }
    
    
    public int addCreateIntfDataExample ()
    {
	try
	    {
		FileWriter file = new FileWriter("IntfData");
		BufferedWriter infoFile = new BufferedWriter (file);

		/* Getting interface Data handle from the example created file */
		InterfaceData interfaceData = null;
		if(mMethod == "InterfaceDataExtrudeP10")
			interfaceData = InterfaceDataExtrudeP10.OtkUtilInterfaceData();
		else if(mMethod == "InterfaceDataInterfaceImport")
			interfaceData = InterfaceDataInterfaceImport.OtkUtilInterfaceData();
		else if(mMethod == "InterfaceDataSurfaceRev")
			interfaceData = InterfaceDataSurfaceRev.OtkUtilInterfaceData();
		
		Session	session = pfcSession.GetCurrentSession ();		
	  	Part newPart = session.CreatePart ("NewIntfData");
		WPart newWPart = (WPart)(newPart);
		WSolid newWSolid = (WSolid)(newWPart);

		WIntfNeutral WIntfNeutral = wfcModel.WIntfNeutral_Create("NewFile", interfaceData);
		IntfNeutral IntfNeutral = (IntfNeutral)(WIntfNeutral);	
			
		newWSolid.ImportAsFeat ((IntfDataSource)IntfNeutral, null, null, null, null);
		
		EdgeRepresentation wEdgeRep = wfcPart.EdgeRepresentation_Create(1,1,1);

	    ConversionOptions wConverOption = wfcPart.ConversionOptions_Create(wEdgeRep, CurveConversionOption.PART_CURVES_AS_DEFAULT, SurfaceConversionOption.PART_SURFACES_AS_DEFAULT);

		// * Getting InterfaceData from the model * /
		InterfaceData newIntfData = newWPart.GetInterfaceData(wConverOption);

		infoFile.write("\t\t\tAfter importing neutral data From the model ");
		infoFile.newLine();
		infoFile.newLine();
		infoFile.write("******************************************************************** ");	 
		infoFile.newLine();
		infoFile.newLine();
	    otkGeometryUtils.OtkUtilInterfaceDataInfo(newIntfData, infoFile);	

		return 0;
		
	    }
	catch (Exception e)
	    {
		System.out.println("1: " + e);
	    }
	return (0);
    }
	
    private String mMethod;
};






